package io.renren.modules.demo.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.renren.common.entity.XlsOrdersGoodsEntity;
import io.renren.common.entity.XlsShopOrdersEntity;
import io.renren.common.entity.XlsUserAwardEntity;
import io.renren.common.enums.CircleLevelEnum;
import io.renren.common.page.PageData;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.Result;
import io.renren.modules.demo.dao.XlsOrdersGoodsDao;
import io.renren.modules.demo.dao.XlsShopOrdersDao;
import io.renren.modules.demo.dto.XlsOrdersGoodsDTO;
import io.renren.modules.demo.dto.XlsShopOrdersDTO;
import io.renren.modules.demo.dto.XlsUserAwardDTO;
import io.renren.modules.demo.service.XlsShopOrdersService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 线上订单表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2020-04-16
 */
@Service
public class XlsShopOrdersServiceImpl extends CrudServiceImpl<XlsShopOrdersDao, XlsShopOrdersEntity, XlsShopOrdersDTO> implements XlsShopOrdersService {

    @Autowired
    private XlsOrdersGoodsDao xlsOrdersGoodsDao;

    @Override
    public QueryWrapper<XlsShopOrdersEntity> getWrapper(Map<String, Object> params) {

        QueryWrapper<XlsShopOrdersEntity> wrapper = new QueryWrapper<>();

        return wrapper;
    }

    @Override
    public PageData<XlsShopOrdersDTO> queryPage(Map<String, Object> params) {
        QueryWrapper<XlsShopOrdersEntity> wrapper = getWrapper(params);
        if(ObjectUtil.isNotEmpty(params.get("orderNo"))) {
            wrapper.eq("xso.order_no", params.get("orderNo"));
        }
//        if(ObjectUtil.isNotEmpty(params.get("username"))) {
//            wrapper.like("xu.username", params.get("username"));
//        }
        IPage<XlsShopOrdersDTO> page = baseDao.queryPage(
                getPage(params, null, false),
                wrapper
        );

        return getPageData(page, currentDtoClass());
    }

    @Override
    public XlsOrdersGoodsDTO selectByOrderId(Long orderId) {
        XlsOrdersGoodsDTO xlsOrdersGoodsDTO = xlsOrdersGoodsDao.selectOrdersGoodsByOrderId(orderId);
        return xlsOrdersGoodsDTO;
    }

}